﻿using System;

using System.Text;
using IAM.Interface.Model.Interface;
using IAM.Interface.Model;
using System.Xml;
using System.Web;

namespace IAM.Interface.Model
{
    /// <summary>
    /// 人员身份信息
    /// </summary>
    [Serializable]
    public class Identity : AbstractConvertObject, IConvertXml
    {
        #region 属性
        private AccountInfo _accountinfo = null;
        private string _name;
        private string _ename;
        private string _firstname;
        private string _email;
        private string _telephone;
        private string _mobile;
        private string _cilaccount;
        private string _companyid;
        private string _companyapbr;
        private string _bgid;
        private string _bgapbr;
        private string _bdid;
        private string _bdapbr;
        private string _buid;
        private string _buapbr;
        private string _costcenter;
        private string _location;
        private AccountInfo _reportto;
        /// <summary>
        /// 人员账号信息
        /// </summary>
        public AccountInfo Accountinfo
        {
            set
            {
                _accountinfo = value;
            }
            get
            {
                return _accountinfo;
            }
        }
        /// <summary>
        /// 中文姓名
        /// </summary>
        public string Name
        {
            set
            {
                _name = value;
            }
            get
            {
                return _name;
            }
        }
        /// <summary>
        /// 英文姓名
        /// </summary>
        public string EName
        {
            set
            {
                _ename = value;
            }
            get
            {
                return _ename;
            }
        }
        /// <summary>
        /// 姓
        /// </summary>
        public string FirstName
        {
            set
            {
                _firstname = value;
            }
            get
            {
                return _firstname;
            }
        }
        /// <summary>
        /// Email地址
        /// </summary>
        public string EMail
        {
            set
            {
                _email = value;
            }
            get
            {
                return _email;
            }
        }
        /// <summary>
        /// 固定电话号码
        /// </summary>
        public string Telephone
        {
            set
            {
                _telephone = value;
            }
            get
            {
                return _telephone;
            }
        }
        /// <summary>
        /// 移动电话号码
        /// </summary>
        public string Mobile
        {
            set
            {
                _mobile = value;
            }
            get
            {
                return _mobile;
            }
        }
        /// <summary>
        /// 人员在X500上的CIL完整信息
        /// </summary>
        public string CILAccount
        {
            set
            {
                _cilaccount = value;
            }
            get
            {
                return _cilaccount;
            }
        }
        /// <summary>
        /// 所属公司id
        /// </summary>
        public string CompanyID
        {
            set
            {
                _companyid = value;
            }
            get
            {
                return _companyid;
            }
        }
        /// <summary>
        /// 所属公司名称
        /// </summary>
        public string CompanyAPBR
        {
            set
            {
                _companyapbr = value;
            }
            get
            {
                return _companyapbr;
            }
        }
        /// <summary>
        /// 上级部门Id
        /// </summary>
        public string BGID
        {
            set
            {
                _bgid = value;
            }
            get
            {
                return _bgid;
            }
        }
        /// <summary>
        /// 上级部门名称
        /// </summary>
        public string BGAPBR
        {
            set
            {
                _bgapbr = value;
            }
            get
            {
                return _bgapbr;
            }
        }
        /// <summary>
        /// 所属平台ID
        /// </summary>
        public string BDID
        {
            set
            {
                _bdid = value;
            }
            get
            {
                return _bdid;
            }
        }
        /// <summary>
        /// 所属平台名称
        /// </summary>
        public string BDAPBR
        {
            set
            {
                _bdapbr = value;
            }
            get
            {
                return _bdapbr;
            }
        }
        /// <summary>
        /// 所属部门id
        /// </summary>
        public string BUID
        {
            set
            {
                _buid = value;
            }
            get
            {
                return _buid;
            }
        }
        /// <summary>
        /// 所属部门名称
        /// </summary>
        public string BUAPBR
        {
            set
            {
                _buapbr = value;
            }
            get
            {
                return _buapbr;
            }
        }
        /// <summary>
        /// 成本中心编号
        /// </summary>
        public string CostCenter
        {
            set
            {
                _costcenter = value;
            }
            get
            {
                return _costcenter;
            }
        }
        /// <summary>
        /// 位置信息
        /// </summary>
        public string Location
        {
            set
            {
                _location = value;
            }
            get
            {
                return _location;
            }
        }
        /// <summary>
        /// 汇报关系
        /// </summary>
        public AccountInfo ReportTo
        {
            get
            {
                return _reportto;
            }
            set
            {
                _reportto = value;
            }
        }
        #endregion
        #region IConvertXml

        public string XMLBoday
        {
            get
            {
                StringBuilder xml = new StringBuilder();
                //1.添加Identity表头
                xml.Append("<Identity>");
                //2.1 添加 AccountInfo 信息
                xml.Append(this.Accountinfo.XML);
                //3.1添加Identity 主信息
                xml.Append("<Name>" + IAM.Interface.Common.EnDeCoding.Encode(this.Name) + "</Name>");
                xml.Append("<EName>" + IAM.Interface.Common.EnDeCoding.Encode(this.EName )+ "</EName>");
                xml.Append("<FirstName>" + IAM.Interface.Common.EnDeCoding.Encode(this.FirstName )+ "</FirstName>");
                xml.Append("<EMail>" + IAM.Interface.Common.EnDeCoding.Encode(this.EMail )+ "</EMail>");
                xml.Append("<Telephone>" + IAM.Interface.Common.EnDeCoding.Encode(this.Telephone )+ "</Telephone>");
                xml.Append("<Mobile>" + IAM.Interface.Common.EnDeCoding.Encode(this.Mobile )+ "</Mobile>");
                xml.Append("<CILAccount>" + IAM.Interface.Common.EnDeCoding.Encode(this.CILAccount )+ "</CILAccount>");

                xml.Append("<CompanyAPBR>" + IAM.Interface.Common.EnDeCoding.Encode(this.CompanyAPBR )+ "</CompanyAPBR>");
                xml.Append("<CompanyID>" + IAM.Interface.Common.EnDeCoding.Encode(this.CompanyID )+ "</CompanyID>");
                xml.Append("<BGAPBR>" + IAM.Interface.Common.EnDeCoding.Encode(this.BGAPBR )+ "</BGAPBR>");
                xml.Append("<BGID>" + IAM.Interface.Common.EnDeCoding.Encode(this.BGID )+ "</BGID>");
                xml.Append("<BDAPBR>" + IAM.Interface.Common.EnDeCoding.Encode(this.BDAPBR )+ "</BDAPBR>");
                xml.Append("<BDID>" + IAM.Interface.Common.EnDeCoding.Encode(this.BDID )+ "</BDID>");
                xml.Append("<BUAPBR>" + IAM.Interface.Common.EnDeCoding.Encode(this.BUAPBR )+ "</BUAPBR>");
                xml.Append("<BUID>" + IAM.Interface.Common.EnDeCoding.Encode(this.BUID )+ "</BUID>");


                xml.Append("<CostCenter>" + IAM.Interface.Common.EnDeCoding.Encode(this.CostCenter )+ "</CostCenter>");
                xml.Append("<Location>" + IAM.Interface.Common.EnDeCoding.Encode(this.Location )+ "</Location>");
                //4.添加ReportTo的xml;
                xml.Append("<ReportTo>");
                xml.Append(this.ReportTo.XML);
                xml.Append("</ReportTo>");

                return xml.ToString();
            }


        }

        public string XMLFinis
        {
            get
            {
                return "</Identity>";
            }
        }
        public string XML
        {
            get
            {
                return XMLBoday + XMLFinis;
            }
        }
        #endregion
        #region AbstractConvertObject
        public override object ConvertToObject()
        {

            //1.填充 Identity

            this.Name = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("Name").InnerText);
            this.EName = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("EName").InnerText);
            this.FirstName = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("FirstName").InnerText);
            this.EMail = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("EMail").InnerText);
            this.Telephone = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("Telephone").InnerText);

            this.Mobile = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("Mobile").InnerText);
            this.CILAccount = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("CILAccount").InnerText);

            this.CompanyAPBR = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("CompanyAPBR").InnerText);
            this.CompanyID = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("CompanyID").InnerText);

            this.BGAPBR = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("BGAPBR").InnerText);
            this.BGID = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("BGID").InnerText);

            this.BDAPBR = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("BDAPBR").InnerText);
            this.BDID = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("BDID").InnerText);

            this.BUAPBR = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("BUAPBR").InnerText);
            this.BUID = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("BUID").InnerText);

            this.CostCenter = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("CostCenter").InnerText);
            this.Location = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("Location").InnerText);
            //2.填充.AccountInfo  
            this.Accountinfo = new AccountInfo();

            this.Accountinfo.CurrentXmlNode = this.CurrentXmlNode.SelectSingleNode("AccountInfo");
            this.Accountinfo = (AccountInfo)this.Accountinfo.ConvertToObject();
            //3.填充Report
            this.ReportTo = new AccountInfo();
            this.ReportTo.CurrentXmlNode = this.CurrentXmlNode.SelectSingleNode("ReportTo/AccountInfo");
            this.ReportTo = (AccountInfo)this.ReportTo.ConvertToObject();
            return this;
        }
        #endregion
    }
}
